<!DOCTYPE html>
<html lang="en" xmlns:th = "http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/main.css">
    <link rel="stylesheet" href="./css/book.css">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/search.css">
    <link rel="shortcut icon" href="img/starfall.png" type="image/x-icon">
    <title th:if="${session.search == null}">搜索</title>
    <title th:else="${session.search == null}" th:text="'搜索-'+${session.search}">Search</title>
</head>
<body background="./img/bg.png">
<ul class="ul">
    <li class="li_home"><a class="a_home" href="/home">首页</a></li>
    <li><a href="/topic">主题</a></li>
    <li><a href="https://www.minecraft.net/zh-hans">Minecraft</a></li>
    <li><a href="https://minecraft.fandom.com/zh/wiki/Minecraft_Wiki">Minecraft Wiki</a></li>
    <div class="minSearch">
        <form action="/topic/search" method="get">
            <div>
                <input type="text" name="search" placeholder="搜你所想"><button type="submit"></button>
            </div>
        </form>
    </div>
    <li th:if="${session.user != null}" class="li_user"><img th:src="@{'/head_img/'+${session.user.head}}" alt="">
        <div class="menu">
            <p th:text="${session.user.name}">User</p>
            <div class="exp">
                <input class="expBarValue" type="hidden" th:value="${session.userExp.present}">
                <div class="expBar"></div>
            </div>
            <span class="level"><span th:text="'Lv:'+${session.user.level}">Lv:1</span>&ensp;&ensp;<span th:text="${session.userExp.exp}+'/'+${session.userExp.maxExp}">0/1</span></span>
            <div class="operate">
                <a class="ul_border" href="/set">设置</a>
                <a class="ul_border" href="/signIn">签到</a>
                <a class="ul_border" href="/exit">退出</a>
            </div>
        </div>
    </li>
    <script src="./js/exp.js"></script>
    <li th:if="${session.user == null}" class="li_user" ><a href="/login">! 请登录 !</a></li>
</ul>
<div class="search">
    <form action="/topic/search" method="get">
        <select name="select">
            <option th:if="${session.searchType != null}" th:value="${session.searchType}" th:text="${session.searchTypeCN}" hidden></option>
            <option value="all">综合</option>
            <option value="title">标题</option>
            <option value="content">内容</option>
            <option value="author">作者</option>
        </select><input class="key" type="text" name="search" placeholder="搜索主题" th:value="${session.search}"><button type="submit"></button>
    </form>
</div>
<div class="main">
    <div class="book">
        <div class="top"></div>
        <div class="left"></div>
        <div class="right"></div>
        <div class="bookCenter">
            <div class="result">
                <table>
                    <tbody th:if="${#lists.isEmpty(session.searchTopic)}">
                        <tr>
                            <th style="text-align: center">你快搜！现在没有任何东西</th>
                        </tr>
                    </tbody>
                    <tbody th:else="${#lists.isEmpty(session.searchTopic)}" th:each="topic : ${session.searchTopic}">
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <th><a class="keyContent" th:href="'/topic/html?html='+${topic.id}" th:text="${topic.title}">主123题</a></th>
                        </tr>
                        <tr>
                            <td>评论:<span th:text="${topic.comment}">111</span> - 查看:<span th:text="${topic.view}">111</span></td>
                        </tr>
                        <tr>
                            <td th:with="content=${#strings.replace(topic.content.replaceAll('<[^>]+>','').replaceAll('\!\[(.*?)\]\((.*?)\)','').replaceAll('\[(.*?)\]\((.*?)\)','').replaceAll('#','').replaceAll('>',''),'*','')}">
    <!--                                                                                                                    说明下，这串有点复杂，就是去除html标签，及去除特殊样式字符的    #strings.substring(#strings.replace(topic.content.replaceAll('<[^>]+>','').replaceAll('#','').replaceAll('>',''),'*',''),0,180)-->
                                <div class="keyContent" th:if="${content.length() >= 170 && #strings.indexOf(content,session.search) < 170}" th:text="${#strings.substring(content,0,170)+'......'}">asdasdad123asdasd</div>
                                <div class="keyContent" th:if="${content.length() >= 170 && #strings.indexOf(content,session.search) >= 170}" th:text="${#strings.substring(content,#strings.indexOf(content,session.search) - 85 + (#strings.length(session.search)),#strings.indexOf(content,session.search) + 85 - (#strings.length(session.search)) )+'......'}">asdasdad123asdasd</div>
                                <div class="keyContent" th:if="${content.length() < 170}" th:text="${content}">内容内容内容内容内容内容内容123内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容</div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span th:text="${topic.date}">1000-01-01</span>
                                -
                                <span><a th:href="'/personal?user='+${topic.user}" th:text="${topic.username}">作者</a></span>
                                -
                                <span><a th:href="'/topic?label='+${topic.labelHref}" th:text="${topic.label}">插件</a></span>
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="page" th:if="${session.search != null}">
                <a th:href="'javascript:'+|page(1,${session.searchPage.lastPage},'${session.search}','${session.searchType}')|" class="back"></a>
                <a th:href="'javascript:'+|page(${session.searchPage.page - 1},${session.searchPage.lastPage},'${session.search}','${session.searchType}')|" class="pre"></a>
                <span th:text="${session.searchPage.page} + '/' + ${session.searchPage.lastPage}">1/2</span>
                <a th:href="'javascript:'+|page(${session.searchPage.page + 1},${session.searchPage.lastPage},'${session.search}','${session.searchType}')|" class="next"></a>
                <a th:href="'javascript:'+|page(${session.searchPage.lastPage},${session.searchPage.lastPage},'${session.search}','${session.searchType}')|" class="last"></a>
            </div>
            <script src="./js/search.js"></script>
        </div>
        <div class="bottom"></div>
    </div>
</div>
<div class="tail">
    <p>StarFall<br>始于2016</p>
</div>
</body>
</html>